package com.atguigu.hbase.filter;

import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.PageFilter;
import org.apache.hadoop.hbase.util.Bytes;

import java.io.IOException;

public class PageFilterTest {

    public static void main(String[] args) throws IOException {
        Filter filter = new PageFilter(15);

        int totalRows = 0;
        byte[] lastRow = null;

        while (true) {
            Scan scan = new Scan();
            scan.setFilter(filter);
            if (lastRow != null) {
                byte[] startRow = Bytes.add(lastRow, POSTFIX); //
                System.out.println("start row:" + Bytes.toStringBinary(startRow));
                scan.setStartRow(startRow);
            }

            ResultScanner scanner = table.getScanner(scan);
            int localRows = 0;
            Result result;
            while ((result = scanner.next()) != null) {
                System.out.println(localRows++ +": " + result);
                totalRows++;
                lastRow = result.getRow();
            }
            scanner.close();
            if (localRows == 0) break;
        }

        System.out.println("total rows:" + totalRows);
    }
}
